package com.lscdu.gulimall.ruoyi_springboot.service.impl;

import com.lscdu.gulimall.ruoyi_springboot.mapper.SysMenuMapper;
import com.lscdu.gulimall.ruoyi_springboot.service.ISysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @author 啊昌
 * @date 2024/9/10 10:21
 * SysMenuServiceImpl 菜单 业务层处理
 */
@Service
public class SysMenuServiceImpl implements ISysMenuService {


	@Autowired
	private SysMenuMapper menuMapper;

	@Override
	public Set<String> selectMenuPermsByUserId(Long userId) {
		List<String> perms = menuMapper.selectMenuPermsByUserId(userId);
		Set<String> permsSet = new HashSet<>();
		for (String perm : perms) {
			if (perm!=null) {
				permsSet.addAll(Arrays.asList(perm.trim().split(",")));
			}
		}
		return permsSet;
	}

	/**
	 * 根据角色ID查询权限
	 *
	 * @param roleId 角色ID
	 * @return 权限列表
	 */
	@Override
	public Set<String> selectMenuPermsByRoleId(Long roleId) {
		//用户ID 查询权限
		List<String> perms = menuMapper.selectMenuPermsByRoleId(roleId);
		Set<String> permsSet = new HashSet<>();
		for (String perm : perms) {
			if (perm !=null) {
				permsSet.addAll(Arrays.asList(perm.trim().split(",")));
			}
		}
		return permsSet;
	}
}
